##
##  This file is part of the PlantSim simulation package
##
##  Copyright 2010 by Carl D. Sorensen
##

from Tkinter import *

class ProcessStep:
  def __init__(self, master, stepnumber, idlecolor, workingcolor,
               textcolor, time):
    self.idleColor = idlecolor
    self.workingColor = workingcolor
    self.textColor = textcolor
    self.stepTime = time
    self.step = stepnumber
    self.doneWip = 0
    self.Wip = 0
    self.batchSize = 0
    self.idle = True
    self.setup = False
    self.sharesRM = False
    self.WipCost = 0
    self.frame = Frame(master, width = 80, height = 60)
    self.frame.pack()
    self.OutputWip = Label(self.frame, text="OutWIP", bg = "white")
    self.OutputWip.place(relx = 0.5, relwidth = 1,
                         relheight = 0.33, rely = 0.16, anchor = CENTER)
    self.StepNumber = Label(self.frame, text="Step")
    self.StepNumber.place(relx = 0.5, relwidth = 1,
                         relheight = 0.33,rely = 0.5, anchor = CENTER)
    self.StepTime = Label(self.frame, text = "Time")
    self.StepTime.place(relx = 0.85, relwidth = 0.3,
                         relheight = 0.34,rely = 0.83, anchor = CENTER)
    self.WipWaiting = Label(self.frame, text = "WIP")
    self.WipWaiting.place(relx = 0.15, relwidth = 0.3,
                         relheight = 0.34,rely = 0.83, anchor = CENTER)
    self.BatchSize = Label(self.frame, text="Batch")
    self.BatchSize.place(relx = 0.5, relwidth = 0.4,
                         relheight = 0.34,rely = 0.83, anchor = CENTER)
    self.redraw ()

  def redraw(self):
    bgcolor = self.idleColor if self.idle else self.workingColor
    self.OutputWip.config(text="{0}".format(self.doneWip))
    steptext = "+Step {0}" if self.setup else "Step {0}"
    self.StepNumber.config(text=steptext.format(self.step),
                            bg= bgcolor, fg=self.textColor)
    self.StepTime.config(text = "{0}".format(self.stepTime),
                            bg=bgcolor, fg=self.textColor)
    self.WipWaiting.config(text = "{0}".format(self.Wip),
                            bg=bgcolor, fg=self.textColor)
    self.BatchSize.config(text = "({0})".format(self.batchSize),
                            bg=bgcolor, fg=self.textColor)

  def setBatch(self, batch):
    self.batchSize = batch
    self.redraw()

  def startSetup(self):
    self.setup = True
    self.redraw()

  def clearSetup(self):
    self.setup = False
    self.redraw()

  def setActive(self):
    self.idle = False
    self.redraw()

  def setIdle(self):
    self.idle = True
    self.redraw()

  def setSharing(self, value):
    self.sharesRM = value

  def destroy(self):
    print "IN DESTROY"
#    for child in self.frame.children:
#      print child
#      self.frame.children[child].place_forget()
#    self.frame.destroy
    self.frame.pack_forget()
#    self.master.update()
